/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import clases.*;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.table.TableColumn;

/**
 *
 * @author ser
 */
public class dlgAcu extends javax.swing.JDialog {

    private ClsDatabase bd = new ClsDatabase();
    DefaultComboBoxModel modelCboUnidad = new DefaultComboBoxModel();
    ClsContraladorEventos controlEvent = new ClsContraladorEventos();
//    private ClsSeguridad seguridad = new ClsSeguridad();
//    private ClsSesion sesion = new ClsSesion();
    private ClsMetodos metodos = new ClsMetodos();
    DefaultComboBoxModel modelCboTipoInsumo = new DefaultComboBoxModel();
    int c1;
    String accion = "N";

    public dlgAcu(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);

    }

    public dlgAcu(java.awt.Frame parent, boolean modal, String val) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        String codigo;
        metodos.comboboxLlenar(cboUnidades, modelCboUnidad, "SELECT idunidad,concat(nombre,'[',simbolo,']') FROM unidad");
        if (val.equals("")) {
            codigo = metodos.generarCodigollaves("select substring(idpartida,3,4) from partida_base ", 4);
            codigo = "H_" + codigo;
            accion = "N";
            this.setName(this.getName()+"-Nuevo");
//             jTextField1.setText("Pd_000001");
        } else {
            accion = "E";
            codigo = val;
            Object[][] array_datos_partida = bd.select("partida_base", "idpartida,nombre,metrado,precio,tipo,idpartida_generica,idunidad", "idpartida='" + codigo + "'");
            txtNombre.setText(array_datos_partida[0][1].toString());
            txtRendimiento.setText(array_datos_partida[0][2].toString());
            txtTotal.setText(array_datos_partida[0][3].toString());
            cboUnidades.setSelectedIndex(modelCboUnidad.getIndexOf(array_datos_partida[0][6].toString()));
            this.setName(this.getName()+"-Modificar");
        }
        accion_nuevo();
        txtCodigo.setText(codigo);
        c1 = 0;
        tblPartida.getColumnModel().getColumn(0).setCellRenderer(tblPartida.getTableHeader().getDefaultRenderer());




        metodos.comboboxLlenarMas(cboTipoInsumo, modelCboTipoInsumo, "SELECT idinsumo_tipo,nombre FROM insumo_tipo");
        cargar_insumos("");
        cargar_partidas_detalle(codigo);
        c1 = 1;
//        Object[] fila = new Object[2];
//        ImageIcon icon = new ImageIcon(getClass().getResource("/resource/agregar.png"));
//        fila[0] = new JLabel(icon);
//        fila[1] = "Presupuesto en Blanco";


    }

    public void accion_nuevo() {
        if (accion.equals("N")) {
            btnEditar.setEnabled(false);
            btnAgregar.setEnabled(false);
            btnQuitar.setEnabled(false);
        }
    }

    public void cargar_insumos(String nombre) {
        metodos.tablaLlenaSql(tblInsumos,
                "i.idinsumo,i.nombre,i.precio,t.nombre,u.simbolo,i.estado ",
                "FROM insumo i,insumo_tipo t,unidad u "
                + "WHERE t.idinsumo_tipo=i.idinsumo_tipo and u.idunidad=i.idunidad and i.nombre like '%" + nombre + "%' and t.idinsumo_tipo like '" + modelCboTipoInsumo.getElementAt(cboTipoInsumo.getSelectedIndex()) + "%' "
                + "ORDER BY i.idinsumo");

    }

    public void cargar_partidas_detalle(String nombre) {
        metodos.tablaLlenaSql(tblPartida,
                " pd.idinsumo,t.nombre,i.nombre,u.simbolo,pd.medida,pd.precio_unitario,pd.precio_parcial ",
                "FROM partida_base_detalle pd, insumo i,insumo_tipo t,unidad u "
                + "WHERE pd.idinsumo=i.idinsumo and  t.idinsumo_tipo=i.idinsumo_tipo and u.idunidad=i.idunidad and pd.idpartida='" + nombre + "' "
                + "ORDER BY i.idinsumo ");

    }

    public void agregar_insumo() {
        if (txtNombre.getText().trim().length() == 0) {
            javax.swing.JOptionPane.showMessageDialog(this, "Ingrese el nombre de la partida");
            return;
        }
        if (cboUnidades.getSelectedIndex() == -1) {
            javax.swing.JOptionPane.showMessageDialog(this, "Seleccione la unidad de la partida");
            return;
        }
        if (txtRendimiento.getText().trim().length() == 0) {
            txtRendimiento.setText("0");
        }
        if (txtTotal.getText().trim().length() == 0) {
            txtTotal.setText("0");
        }
        int fila = tblInsumos.getSelectedRow();
        if (fila != -1) {
//            if (bd.verif_repite("select idpartida from partida_base where idpartida='" + jTextField1.getText() + "'") == false) {
//                bd.insert("partida_base", "idpartida,nombre,metrado,precio,tipo,idpartida_generica,idunidad,uso,estado", "'" + jTextField1.getText() + "','" + jTextField2.getText() + "','" + jTextField3.getText() + "','" + jTextField4.getText() + "','E','1','" + modelCboUnidad.getElementAt(jComboBox2.getSelectedIndex()) + "','N','A'");
//            }
            if (bd.verif_repite("select idpartida from partida_base_detalle where  idpartida='" + txtCodigo.getText() + "' and idinsumo='" + tblInsumos.getValueAt(fila, 0) + "'")) {
                javax.swing.JOptionPane.showMessageDialog(this, "El insumo ya existe");
                return;
            }
            if (txtPrecio.getText().trim().length() == 0) {
                javax.swing.JOptionPane.showMessageDialog(this, "El ingrese el precio del insumo");
                return;
            }
            if (txtCantidad.getText().trim().length() == 0) {
                String tipo = "";
                if (tblInsumos.getValueAt(fila, 3).toString().equals("MANO DE OBRA")) {
                    tipo = "Cuadrilla";
                } else {
                    tipo = "Cantidad";
                }
                javax.swing.JOptionPane.showMessageDialog(this, "El ingrese la " + tipo + " del insumo");
                return;
            }
            bd.insert("partida_base_detalle", "idpartida,idinsumo,medida,precio_unitario,precio_parcial", "'" + txtCodigo.getText() + "','" + tblInsumos.getValueAt(fila, 0) + "','" + txtCantidad.getText() + "','" + txtPrecio.getText() + "','" + (Integer.parseInt(txtCantidad.getText()) * Integer.parseInt(txtPrecio.getText())) + "'");
            cargar_partidas_detalle(txtCodigo.getText());

//            for (int i = 0; i < jTable1.getRowCount(); i++) {
//                System.out.println(jTable1.getValueAt(i, 6).toString());
//                total = total + Integer.getInteger(jTable1.getValueAt(i, 6).toString());
//            }

            actulizar_total_partida();
            


        }

    }

    public void actulizar_total_partida() {
        Object[][] array_datos_total = bd.select("partida_base_detalle", "sum(precio_parcial)", " idpartida='" + txtCodigo.getText() + "'");
        if(array_datos_total != null){
            txtTotal.setText(array_datos_total[0][0].toString());
        }else{
            txtTotal.setText("0");
        }

        bd.update("partida_base", "precio='" + txtTotal.getText() + "'", " idpartida='" + txtCodigo.getText() + "'");
    }

    public void quitar_insumos_partida() {
        int fila = tblPartida.getSelectedRow();
        if (fila != -1) {
            bd.delete("partida_base_detalle", "idpartida='" + txtCodigo.getText() + "' and idinsumo='" + tblPartida.getValueAt(fila, 0) + "'");
            actulizar_total_partida();
            cargar_partidas_detalle(txtCodigo.getText());
            
        }
    }

    public void agragar_datos() {
        int fila = tblInsumos.getSelectedRow();
        if (fila != -1) {
            if (tblInsumos.getValueAt(fila, 3).toString().equals("MANO DE OBRA")) {
                jLabel3.setText("Cuadrilla:");
            } else {
                jLabel3.setText("Cantidad:");
            }
            txtPrecio.setText(tblInsumos.getValueAt(fila, 2).toString());
            txtCantidad.setText("0");
        }
    }

    public void actulizarPartida() {
        if (cboUnidades.getSelectedIndex() == -1) {
            javax.swing.JOptionPane.showMessageDialog(this, "Seleccione la unidad de la partida");
            return;
        }
        if (txtRendimiento.getText().trim().length() == 0) {
            txtRendimiento.setText("0");
        }
        if (txtTotal.getText().trim().length() == 0) {
            txtTotal.setText("0");
        }
        if (accion.equals("N")) {
            bd.insert("partida_base", "idpartida,nombre,metrado,precio,tipo,idpartida_generica,idunidad,uso,estado", "'" + txtCodigo.getText() + "','" + txtNombre.getText() + "','" + txtRendimiento.getText() + "','" + txtTotal.getText() + "','E','1','" + modelCboUnidad.getElementAt(cboUnidades.getSelectedIndex()) + "','N','A'");
        } else {
            bd.update("partida_base", "nombre='" + txtNombre.getText() + "',metrado='" + txtRendimiento.getText() + "',precio='" + txtTotal.getText() + "',idunidad='" + modelCboUnidad.getElementAt(cboUnidades.getSelectedIndex()) + "'", " idpartida='" + txtCodigo.getText() + "'");
        }

        btnEditar.setEnabled(true);
        btnAgregar.setEnabled(true);
        btnQuitar.setEnabled(true);
        accion = "E";

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPartida = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel3 = new javax.swing.JPanel();
        txtNombre = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtRendimiento = new javax.swing.JTextField();
        txtTotal = new javax.swing.JTextField();
        cboUnidades = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        btnGuardar = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblInsumos = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        cboTipoInsumo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        btnAgregar = new javax.swing.JButton();
        btnQuitar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtPrecio = new javax.swing.JTextField();
        btnEditar = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Analisis de costos unitarios");

        jPanel2.setBackground(new java.awt.Color(225, 235, 247));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle partida"));
        jPanel1.setOpaque(false);

        tblPartida.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cod.", "Tipo", "Descripción", "Und.", "Cant.", "P. unitario", "P. parcial"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblPartida);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 729, Short.MAX_VALUE)
                .addGap(5, 5, 5))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
        );

        jPanel2.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 151, 751, 190));
        jPanel2.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 38, 771, 10));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos partida"));
        jPanel3.setOpaque(false);

        txtCodigo.setEditable(false);

        jLabel1.setText("codigo:");

        jLabel2.setText("Nombre:");

        jLabel5.setText("Rendimiento:");

        jLabel6.setText("Total:");

        txtRendimiento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRendimientoKeyTyped(evt);
            }
        });

        txtTotal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTotalKeyTyped(evt);
            }
        });

        jLabel7.setText("Und.");

        btnGuardar.setText("Guardar");
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(47, 47, 47)
                        .addComponent(btnGuardar))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRendimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cboUnidades, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addComponent(btnGuardar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtRendimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboUnidades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6)
                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel2.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 54, 751, -1));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleccion de Insumos"));
        jPanel4.setOpaque(false);

        tblInsumos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Nombre", "Precio", "Tipo Insumo", "Unidad", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblInsumos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblInsumos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblInsumosMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblInsumos);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Buscar:");

        txtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBuscarActionPerformed(evt);
            }
        });
        txtBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBuscarKeyReleased(evt);
            }
        });

        cboTipoInsumo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboTipoInsumo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTipoInsumoActionPerformed(evt);
            }
        });

        jLabel9.setText("Tipo insumo:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35)
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(cboTipoInsumo, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 167, Short.MAX_VALUE)))
                .addGap(5, 5, 5))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboTipoInsumo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 396, 750, -1));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("datos de detalle"));
        jPanel5.setOpaque(false);

        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnQuitar.setText("Quitar");
        btnQuitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarActionPerformed(evt);
            }
        });

        jLabel3.setText("Cantidad:");

        txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadKeyTyped(evt);
            }
        });

        jLabel8.setText("Precio:");

        txtPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPrecioKeyTyped(evt);
            }
        });

        btnEditar.setText("Editar");
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(106, 106, 106)
                .addComponent(btnAgregar)
                .addGap(18, 18, 18)
                .addComponent(btnEditar)
                .addGap(18, 18, 18)
                .addComponent(btnQuitar)
                .addContainerGap(91, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3)
                .addComponent(jLabel8)
                .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btnAgregar)
                .addComponent(btnEditar))
            .addComponent(btnQuitar)
        );

        jPanel2.add(jPanel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 344, 751, -1));

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/icon/principales/fondo_dialog.jpg"))); // NOI18N
        jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 450, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblInsumosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblInsumosMouseClicked
        agragar_datos();

    }//GEN-LAST:event_tblInsumosMouseClicked

    private void txtBuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBuscarKeyReleased
        cargar_insumos(txtBuscar.getText());
    }//GEN-LAST:event_txtBuscarKeyReleased

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        agregar_insumo();
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void btnQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarActionPerformed
        quitar_insumos_partida();
    }//GEN-LAST:event_btnQuitarActionPerformed

    private void txtBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBuscarActionPerformed
    }//GEN-LAST:event_txtBuscarActionPerformed

    private void cboTipoInsumoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTipoInsumoActionPerformed
        if (c1 == 1) {
            cargar_insumos(txtBuscar.getText());
        }
    }//GEN-LAST:event_cboTipoInsumoActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        actulizarPartida();
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void txtRendimientoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRendimientoKeyTyped
        controlEvent.numero1Punto_2Decimal(evt, txtRendimiento);
    }//GEN-LAST:event_txtRendimientoKeyTyped

    private void txtTotalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTotalKeyTyped
        controlEvent.numero1Punto_2Decimal(evt, txtTotal);
    }//GEN-LAST:event_txtTotalKeyTyped

    private void txtPrecioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioKeyTyped
        controlEvent.numero1Punto_2Decimal(evt, txtPrecio);
    }//GEN-LAST:event_txtPrecioKeyTyped

    private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadKeyTyped
        controlEvent.numero1Punto_2Decimal(evt, txtCantidad);
    }//GEN-LAST:event_txtCantidadKeyTyped

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEditarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgAcu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgAcu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgAcu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgAcu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgAcu dialog = new dlgAcu(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnQuitar;
    private javax.swing.JComboBox cboTipoInsumo;
    private javax.swing.JComboBox cboUnidades;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable tblInsumos;
    private javax.swing.JTable tblPartida;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtPrecio;
    private javax.swing.JTextField txtRendimiento;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
